package com.shun.util;


import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;



public class MyBatisUtils {
    private static SqlSessionFactory ssf;
    static {
            //此处替换为你的mybatis主配置文件，我的是SqlMapConfig.xml
            String config = "Mybatis-Config.xml";
            //读取配置文件
            //使用SqlSessionFactoryBuilder()创建SqlSessionFactory
            SqlSessionFactoryBuilder ssfb=new SqlSessionFactoryBuilder();
            ssf=ssfb.build(MyBatisUtils.class.getClassLoader().getResourceAsStream(config));
    }
    //获取sqlSession方法
    public static SqlSessionFactory getSqlSessionFactory(){
        return ssf;
    }
    public static SqlSession getSqlSession(){
        SqlSession sqlSession = getSqlSessionFactory().openSession();
        return sqlSession;
    }
}